package top_request

import (
	"fmt"
	"gitee.com/ha666/golibs"
	"net/url"
	"sort"
	"strings"
)

func top_sign(params url.Values, secret string) string {
	keys := make([]string, 0, len(params))
	for key := range params {
		keys = append(keys, key)
	}
	sort.Strings(keys)
	data := golibs.NewStringBuilder()
	for _, k := range keys {
		if strings.EqualFold(k, "") || strings.EqualFold(params[k][0], "") {
			continue
		}
		data.Append(k).Append(params[k][0])
	}
	return fmt.Sprintf("%X", golibs.HmacMd5([]byte(data.ToString()), []byte(secret)))
}
